package com.kotlin.flong.flow

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.runBlocking

/**
 * @Author:liangjl
 * @Date: 2020/7/11-21:04
 * @Eamil:jilongliang@sina.com
 * @Description:
 */
private fun myMethod(): Flow<String> = flow {
    for (a in 1..3) {
        println("emiting $a")
        emit(a)
    }
}.map { value ->
    check(value <= 1) {
        "Catch on $value"
    }
    "String $value"
}

fun main() = runBlocking<Unit> {

    try {
        myMethod().collect { println(it) }
    } catch (e: Throwable) {
        println("main-->" + e.message)
    }
}